package com.oscarmovie.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.oscarmovie.Constants;
import com.oscarmovie.model.Language;
import com.oscarmovie.service.LanguageService;

public class LanguageAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private LanguageService languageService;

	private Language language;
	private List<Language> languages;

	public String add() throws Exception {
		setLanguage(null);
		return Constants.ADD;
	}
	
	public String edit() throws Exception {
		loadAll();
		load();
		return Constants.EDIT;
	}
	
	public String save() throws Exception {
		languageService.save(language);
		return edit();
	}

	public String load() throws Exception {
		setLanguage(languageService.load(language.getId()));
		return SUCCESS;
	}

	public String loadAll() throws Exception {
		this.languages = languageService.loadAll();
		return SUCCESS;
	}

	public List<Language> getLanguages() {
		return languages;
	}

	public void setLanguageService(LanguageService languageService) {
		this.languageService = languageService;
	}

	public void setLanguage(Language language) {
		this.language = language;
	}

	public Language getLanguage() {
		return language;
	}

}
